package com.zhuiyun.project.api.recipe.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhuiyun.project.annotation.OptLog;
import com.zhuiyun.project.api.recipe.entity.Recipe;
import com.zhuiyun.project.api.recipe.mapper.RecipeMapper;
import com.zhuiyun.project.api.recipe.model.RecipeModel;
import com.zhuiyun.project.api.recipe.service.RecipeService;
import com.zhuiyun.project.api.venuemanagement.model.VenueAddModel;
import com.zhuiyun.project.api.venuemanagement.model.VenueUpdateModel;
import com.zhuiyun.project.common.errorCode.CommonException;
import com.zhuiyun.project.common.response.CommonResult;
import com.zhuiyun.project.utils.constants.CommonConstants;
import com.zhuiyun.project.utils.pageUtil.PageRequest;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("/Recipe")
public class RecipeController {
    @Resource
    RecipeService recipeService;

    @Resource
    RecipeMapper recipeMapper;
    /*
     * @Author MJL
     * @Description 添加食谱信息
     * @Date 2023/11/20 13:53
     * @Return
     */
    @PostMapping("/addRecipe")
    @ApiOperation(value = "添加食谱信息")
    @OptLog(modular = "食谱管理",type = CommonConstants.ADD,describe = "添加食谱")
    public CommonResult addRecipe(RecipeModel recipeModel, MultipartFile file) throws CommonException {
        log.info("新增食谱");
        return CommonResult.ok(recipeService.addRecipe(recipeModel,file));
    }

    /*
     * @Author MJL
     * @Description 修改食谱信息
     * @Date 2023/11/20 14:09
     * @Return
     */
    @PutMapping("/updateRecipe")
    @ApiOperation(value = "修改食谱信息")
    @OptLog(modular = "食谱管理",type = CommonConstants.ADD,describe = "修改食谱")
    public CommonResult updateRecipe(RecipeModel recipeModel, MultipartFile file) throws CommonException {
        return CommonResult.ok(recipeService.updateRecipe(recipeModel,file));
    }

    /*
     * @Author MJL
     * @Description 删除食谱信息
     * @Date 2023/11/20 14:09
     * @Return
     */
    @DeleteMapping("/deleteRecipe")
    @ApiOperation(value = "删除食谱信息")
    @OptLog(modular = "食谱管理",type = CommonConstants.ADD,describe = "删除食谱")
    public CommonResult deleteRecipe(Integer id) throws CommonException {
        return CommonResult.ok(recipeService.deleteRecipe(id));
    }

    @GetMapping("/getRevipeByPage")
    @ApiOperation(value = "食谱管理的分页查询方法")
    @OptLog(modular = "食谱管理", type = CommonConstants.SELECT, describe = "分页查询")
    public CommonResult getRevipeByPage(RecipeModel recipeModel, PageRequest pageRequest) throws CommonException {
        return recipeService.getRevipeByPage(recipeModel,pageRequest);
    }

    /*
     * @Author xy
     * @Description todo 查询食谱图片
     * @Date 2023/11/28 9:56
     * @Return
     * @param
     */
    @GetMapping("/listrecipeimg")
    @ApiOperation(value = "查询课程图片")
    @OptLog(modular = "课程管理", type = CommonConstants.SELECT, describe = "查询课程图片")
    public CommonResult listrecipeimg() {
        QueryWrapper<Recipe> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("recipe_file_id");
        List<Recipe> recipes = recipeMapper.selectList(queryWrapper);
        return CommonResult.ok(recipes);
    }
}
